<?php
declare (strict_types = 1);
namespace app\course\model\coupon;

use app\common\model\BaseModel;
use think\model\relation\BelongsTo;

/**
 * 线下卡券模型
 */
class CouponOffline extends BaseModel
{
    /**
     * 表名
     * @var string
     */
    protected $name   = 'coupon_offline';
    /**
     * 设置自动写入时间
     * @var boolean
     */
    protected $autoWriteTimestamp = true;


    /**
     * 定义字段类型
     * @var array
     */
    protected $type = [
        'id'          => 'integer',
        'update_time' => 'integer',
        'create_time' => 'integer',
    ];

    public function coupon(): BelongsTo
    {
        return $this->belongsTo(Coupon::class, 'coupon_id');
    }

    public function couponCanExchange(): BelongsTo
    {
        return $this->belongsTo(Coupon::class, 'coupon_id')->scope(['canExchange']);
    }

}
